import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Main {
    public static void main(String[] args) {
        // 数据库连接信息
        String url = "jdbc:mysql://localhost:3306/databasename";
        String username = "root";
        String password = "zk1314521";

        // SQL查询语句
        String query = "SELECT * FROM userInfo";

        // 使用try-with-resources自动关闭资源
        try (Connection connection = DriverManager.getConnection(url, username, password);
             Statement statement = connection.createStatement();
             ResultSet resultSet = statement.executeQuery(query)) {

            // 遍历结果集并输出数据
            while (resultSet.next()) {
                String name = resultSet.getString("username");
                String passwords = resultSet.getString("password");
                String sex = resultSet.getString("sex");
                System.out.println("name: " + name + ", password:" + passwords + ", sex:" + sex);
                System.out.println("--");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}